﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InvestmentIntelligence.DB;

namespace InvestmentIntelligence.Data.Repository.EFImplementation
{
    using InvestmentIntelligence.DB.Utils;
    using InvestmentIntelligence.DbModel;

    public class IIPRepository<TEntity> : BaseRepository<TEntity>
        where TEntity : class
    {
        protected override Func<System.Data.Entity.DbContext> DbContext
        {
            get { return ()=>new IIPEntities(); }
        }

        protected T RunUnitOfWork<T>(Func<IIPEntities, T> f)
        {
            using (var dc = new IIPEntities())
            {
                var query = f(dc);
                return query;
            }
        }


        protected T InternalGet<T, T2>(Func<IIPEntities, IQueryable<T2>> b, Func<IQueryable<T2>, T> f)
        {
            return RunUnitOfWork(dc =>
            {
                var souurceQueryable = b(dc);
                var query = f(souurceQueryable);
                return query;
            });
        }


        protected string GetTableName()
        {
            using (var dc = new IIPEntities())
            {
                return dc.GetTableName<TEntity>();
            }
        }

    }
}
